#include "IceLink.h"
#include "BaseTimer.h"

using namespace cm_nat;

int main()
{
    SocketReactor reactor;
    reactor.setTimeout(Poco::Timespan(1,0,0,0,0));

    ByteBufferPool bpool;
    bpool.setup(10, 200);

    BaseTimer timer;
    timer.setup();

    //SocketAddress stunSa("stun.l.google.com","19302");
    //SocketAddress stunSa("192.168.1.99","3478");
    SocketAddress stunSa("stunserver.org", 3478);

    Thread t;
    t.start(reactor);


    IceLink link( &bpool, &reactor, &timer );
    link.setStunAddress(stunSa);

    NetworkInterface nic = (NetworkInterface::list())[1];
    std::cout<<"\n"<< nic.address().toString()<<"\n"<<nic.displayName();
    link.setup(nic);

    std::string input;
    std::cin>>input;
   //123.152.119.214 62309
   // link.connectToPeer(SocketAddress("123.152.119.214",62439));
    std::cin>>input;
    while(1){
        std::cin>>input;
        ByteBuffer* p_buf = bpool.get(0);
        if( p_buf ){
            p_buf->increaseRef();
            p_buf->setLength(50);
            memset( (void*)(p_buf->Data()), 0, p_buf->Capacity() );
            link.send( p_buf );
        }
    }
    return 0;
}